class jQuery {
  constructor(selector) {
    this.selector = selector
    const res = document.querySelectorAll(selector)
    for(let i = 0; i < res.length; i++) {
      this[i] = res[i]
    }
    this.length = res.length
  }

  get (index) {
    return this[index]
  }

  each (fn) {
    for(let i = 0; i < this.length; i++) {
      fn(this[i])
    }
  }

  on (type, fn) {
    return this.each(function (ele) {
      ele.addEventListener(type, fn, false)
    })
  }
}

const p = new jQuery('p')
console.log(p.get(0))

// 插件
jQuery.prototype.dialog = function (info) {
  alert(info)
}

// 造轮子
class myJQuery extends jQuery {
  constructor(selector) {
    super(selector)
  }

  // 扩展自己的方法
  addClass(className) {
  }

  style(data) {
  }
}